package com.example.javatest.controller;

import com.example.javatest.entity.domain.InfoClass;
import com.example.javatest.entity.domain.InfoSystem;
import com.example.javatest.entity.domain.SupCreateclass;
import com.example.javatest.entity.domain.TbClass;
import com.example.javatest.entity.domain.request.ClassAddRequest;
import com.example.javatest.entity.domain.request.ClassRegisterRequest;
import com.example.javatest.entity.domain.request.ClassRequest;
import com.example.javatest.entity.domain.request.RoleRequest;
import com.example.javatest.service.SupCreateclassService;
import com.example.javatest.service.TbClassService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@CrossOrigin
@RestController
public class classController {

    @Resource
    private TbClassService tbClassService;

    @Resource
    private SupCreateclassService supCreateclassService;

    /**
     * 根据用户ID查询自己所在班级
     * @param classRequest
     * @param httpServletRequest
     * @return
     */
    @PostMapping("/class")
    public TbClass getClassById(@RequestBody ClassRequest classRequest, HttpServletRequest httpServletRequest){
        if(classRequest == null){
            return null;
        }
        int classId = classRequest.getClassId();
        if(classId<1000){
            return null;
        }
        return tbClassService.getClass(classId);
    }

    @GetMapping("searchClass")
    public List<TbClass> searchClass(){
        return tbClassService.list();
    }

    /**
     * 返回所有 新建班级 申请
     * @return
     */
    @GetMapping("/getClassAplyInfo")
    public List<SupCreateclass> getClassAplyInfo(){
        return supCreateclassService.list();
    }

    /**
     * 班级申请提交
     */
    @PostMapping("/supClassCreate")
    public boolean supClassCreate(@RequestBody ClassRegisterRequest classRegisterRequest, HttpServletRequest httpServletRequest){

        if(classRegisterRequest==null){
            return false;
        }
//        String isHandle = classRegisterRequest.getSupHandel();
        String className = classRegisterRequest.getSupClassName();
        String userName = classRegisterRequest.getSupName();
        if(StringUtils.isAnyBlank(className,userName)){
            return false;
        }
        return  supCreateclassService.supCreateClass(className,userName);
    }

    /**
     * 处理班级申请
     */
    @PostMapping("/handleClassAply")
    public boolean handleClassAply(@RequestBody ClassRequest classRequest,HttpServletRequest httpServletRequest){
        if(classRequest == null){
            return false;
        }
        int supId =classRequest.getSupId();
        String className = classRequest.getClassName();
        String Master = classRequest.getClassMaster();
        String isHandle = classRequest.getIsHandle();
        return supCreateclassService.handleClassAply(className,isHandle,Master,supId);
    }
}
